import { CHECKED } from "../../../../../constants/common";

export default {
  required: {
    validate: ({ value }) => !!(value && value.length)
  },
  limit: {
    validate: ({ value, config }) => {
      const { max, min } = config;
      const len = value.length;
      let isValid = true;

      if (CHECKED === max.checked) {
        isValid = len <= max.value;
      }

      if (CHECKED === min.checked) {
        isValid = isValid && len >= min.value;
      }

      return isValid;
    },
    error: ({ config }) => config.subTitle
  }
};